// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   UploadFileServiceImpl.java

package com.hfstu.file.dataaccess.service.impl;

import com.hfstu.file.FileServerInfo;
import com.hfstu.file.dataaccess.dao.IUploadFileDao;
import com.hfstu.file.dataaccess.service.IUploadFileService;
import com.hfstu.file.model.UploadFile;
import com.hfstu.file.utils.FileCleanPolicy;
import com.hfstu.framework.core.orm.Page;
import com.hfstu.framework.core.orm.PageRequest;
import com.hfstu.framework.util.StringUtil;
import java.util.*;

public class UploadFileServiceImpl
	implements IUploadFileService
{

	private IUploadFileDao uploadFileDao;
	private FileCleanPolicy fileCleanPolicy;

	public UploadFileServiceImpl()
	{
		fileCleanPolicy = null;
	}

	public UploadFile save(UploadFile paramUploadFile)
	{
		UploadFile result = uploadFileDao.save(paramUploadFile);
		return result;
	}

	public UploadFile getById(String paramString)
	{
		return uploadFileDao.getById(paramString);
	}

	public UploadFile update(UploadFile paramUploadFile)
	{
		return uploadFileDao.saveOrUpdate(paramUploadFile);
	}

	public List getByIds(String paramArrayOfString[])
	{
		return uploadFileDao.getByIds(paramArrayOfString);
	}

	public boolean deleteById(String paramString)
	{
		UploadFile file = uploadFileDao.getById(paramString);
		String absolutePath = FileServerInfo.getInstance().getAbsolutePath(file);
		uploadFileDao.deleteById(paramString);
		fileCleanPolicy.clean(absolutePath);
		return true;
	}

	public Page findByCondition(PageRequest pageRequest, Map filterPropertyMap, Map sortValueMap)
	{
		StringBuilder hql = new StringBuilder();
		hql.append(" select uploadFile from UploadFile uploadFile");
		StringBuilder whereHql = new StringBuilder();
		whereHql.append(" where 1=1");
		List values = null;
		if (filterPropertyMap != null && !filterPropertyMap.isEmpty())
		{
			values = new ArrayList();
			Object value = null;
			Set keys = filterPropertyMap.keySet();
			for (Iterator iterator = keys.iterator(); iterator.hasNext();)
			{
				String key = (String)iterator.next();
				value = filterPropertyMap.get(key);
				if (key.equals("uploadFile.fileName") && !StringUtil.isNullOrEmpty((String)value))
				{
					whereHql.append(" and uploadFile.fileName like ?");
					values.add((new StringBuilder("%")).append(StringUtil.clean((String)value)).append("%").toString());
				}
				value = null;
			}

		}
		hql.append(whereHql);
		if (sortValueMap != null && !sortValueMap.isEmpty())
			hql.append(" order by ").append((String)sortValueMap.get("sort")).append(" ").append((String)sortValueMap.get("order"));
		return uploadFileDao.findPageByHql(pageRequest, hql.toString(), values.toArray());
	}

	public IUploadFileDao getUploadFileDao()
	{
		return uploadFileDao;
	}

	public void setUploadFileDao(IUploadFileDao uploadFileDao)
	{
		this.uploadFileDao = uploadFileDao;
	}

	public FileCleanPolicy getFileCleanPolicy()
	{
		return fileCleanPolicy;
	}

	public void setFileCleanPolicy(FileCleanPolicy fileCleanPolicy)
	{
		this.fileCleanPolicy = fileCleanPolicy;
	}
}
